<template>
	<view :class="[BackGround]" :style="[{'font-weight':Style,'font-family':Font,height:height + 'px'}]">
		<cu-custom bgColor="bg-gradual-blue" isBack="true" @openMenu="openMenu">
			<view slot="backText">返回</view>
			<view slot="content">档案信息</view>
		</cu-custom>
		<view :class="['margin-xs radius shadow shadow-lg bg-white',BackGroundBox]" v-if="isShow">
			<form @submit="formSubmit" @reset="formReset">
				<view :style="{marginBottom:bottom + 'rpx'}">
					<view class="cu-form-group">
						<view class="title">机器编号</view>
						<input type="text" name="LMACHINENO" disabled :value="deliverplan.LMACHINENO" placeholder="系统自动生成" />
					</view>
					<view class="cu-form-group">
						<view class="title">IP地址</view>
						<input type="text" name="LIP" :value="deliverplan.LIP" placeholder="可选值" />
					</view>
					<view class="cu-form-group">
						<view class="title">机器地址</view>
						<input type="text" name="LMAC" :value="deliverplan.LMAC" placeholder="可选值" />
					</view>
					<view class="cu-form-group">
						<view class="title">生产车间</view>
						<picker @change="PickerChange1" name="LCLASSINDEX" :value="index1" :range="picker1" range-key="LNAME">
							<view class="picker">
								{{index1>-1?picker1[index1].LNAME:'请选择'}}
							</view>
						</picker>
					</view>
					<view class="cu-form-group">
						<view class="title">工序类别</view>
						<picker @change="PickerChange2" name="LTYPE" :value="index2" :range="picker2" range-key="LNAME">
							<view class="picker">
								{{index2>-1?picker2[index2].LNAME:'请选择'}}
							</view>
						</picker>
					</view>
					<view class="cu-form-group">
						<view class="title">机器类型</view>
						<picker @change="PickerChange4" name="LPRCTYPE" :value="index4" :range="picker4" range-key="LNAME">
							<view :class="['picker',index4 === -1 ? 'text-grey5' : 'text-black']">
								{{index4>-1?picker4[index4].LNAME:'请选择'}}
							</view>
						</picker>
					</view>
					<view class="cu-form-group">
						<view class="title">机器型号</view>
						<input type="text" disabled :value="picker4[index4].LCODE" name="LMACHINETYPE" />
					</view>
					<view class="cu-form-group">
						<view class="title">是否有效</view>
						<switch name="LISUSED" @change="SwitchA" :value="deliverplan.LISUSED" :class="deliverplan.LISUSED?'checked':''"
						 :checked="deliverplan.LISUSED"></switch>
					</view>
					<view class="cu-form-group">
						<view class="title">备注</view>
						<input :adjust-position="false" v-model="deliverplan.LREMARK" @focus="focus" @blur="blur"
						 placeholder="请输入备注" type="text" name="LREMARK" />
					</view>
				</view>
				<button-father :Position="'tb-fa-fixed'">
					<button class="cu-btn bg-gradual-red  lg shadow tb-flex cu-btn-new" @tap="deleteall">删除</button>
					<button class="cu-btn bg-gradual-blue  lg shadow tb-flex cu-btn-new" form-type="submit">确认修改</button>
				</button-father>
			</form>
		</view>
		<!--顶部下拉菜单-->
		<zyt-input tui-top-dropdown="tui-top-dropdown" bgcolor="rgba(76, 76, 76, 0.95)" :show="menuShow" :height="0" @close="closeMenu"
		 :zvalue="LREMARK" @zblur="zblur">
		</zyt-input>
		<!---顶部下拉菜单-->
	</view>
</template>

<script>
	import ButtonFather from "@/colorui/components/ButtonFather.vue";
	import zytInput from '@/colorui/components/input.vue'
	import {
		mapGetters
	} from 'vuex'
	import {
		getselectReferList,
		getSelect2
	} from "@/service/selectList.js"
	import {
		postinsert
	} from "@/service/insert.js"
	import {
		postdeleteList
	} from "@/service/deleteList.js"
	import {
		postupdate
	} from '@/service/updateList'
	export default {
		data() {
			return {
				height: this.screenHeight,
				LREMARK: "",
				menuShow: false,
				zvalue: "",
				bottom: 100,
				switchA: true,
				isShow: false,
				LID: "",
				deliverplan: [],
				picker1: [],
				index1: 0,
				picker2: [],
				index2: -1,
				picker4: [],
				index4: 0
			}
		},
		components: {
			ButtonFather,
			zytInput
		},
		computed: {
			...mapGetters(['Style', 'Font', 'BackGround', 'BackGroundBox'])
		},
		onLoad(option) {
			console.log(option);
			this.LID = option.LID
			this.getSelect2()
			// getSelect2(9538,{'LID':option.LID}).then(res => {
			// 	if (res.code === 1) {
			// 		this.deliverplan = res.data
			// 	}
			// })

		},
		methods: {
			async getSelect2() {
				let {
					data
				} = await getSelect2(9538, {
					'LID': this.LID
				})
				data.forEach((val, index) => {
					if (val.LID == this.LID) {
						this.deliverplan = val
					}
				});
				getselectReferList(9538, '表头', 'LCLASSINDEX', {}).then(res => {
					if (res.code != 0) {
						this.picker1 = res.data
						this.picker1.forEach((val, index) => {
							if (val.LNAME == this.deliverplan.LCLASSINDEX) {
								this.index1 = index
							}
						});
					} else {
						this.isShow = true
					}
				})
				getselectReferList(9538, '表头', 'LTYPE', {}).then(res => {
					if (res.code != 0) {
						this.picker2 = res.data
						this.picker2.forEach((val, index) => {
							if (val.LNAME == this.deliverplan.LTYPE) {
								this.index2 = index
							}
						});
					} else {
						this.isShow = true
					}
				})
				getselectReferList(9538, '表头', 'LPRCTYPE', {}).then(res => {
					if (res.code != 0) {
						this.picker4 = res.data
						this.picker4.forEach((val, index) => {
							if (val.LNAME == this.deliverplan.LPRCTYPE) {
								this.index4 = index
							}
						});
						this.isShow = true
					} else {
						this.isShow = true
					}
				})
			},
			PickerChange1(e) {
				this.index1 = e.detail.value
			},
			PickerChange2(e) {
				this.index2 = e.detail.value
			},
			PickerChange4(e) {
				this.index4 = e.detail.value
			},
			SwitchA(e) {
				this.switchA = e.detail.value
				this.deliverplan.LISUSED = e.detail.value
			},
			focus(e) {
				this.menuShow = true
				this.LREMARK = e.detail.value
				this.deliverplan.LREMARK = e.detail.value
			},
			openMenu() {
				this.menuShow = false
			},
			zblur(value) {
				console.log(value);
				this.LREMARK = value
				this.deliverplan.LREMARK = value
			},
			blur() {

			},
			closeMenu() {
				this.menuShow = false
			},
			deleteall() {
				postdeleteList(9538,this.LID,'','').then(res => {
					if(res.code == 1) {
						global.Return = true
						setTimeout(() => {
							uni.navigateBack({
								delta:1
							})
						},500)
						uni.showToast({
							title:'删除成功',
							icon:'success'
						})
					}
				})
			},
			formSubmit(e) {
				e.detail.value['LCLASSINDEX'] = this.picker1[this.index1].LNAME
				e.detail.value['LTYPE'] = this.picker2[this.index2].LNAME
				e.detail.value['LUID'] = 0
				e.detail.value['LSTATERUN'] = 2
				e.detail.value['LPRCTYPE'] = this.picker4[this.index4].LNAME
				e.detail.value['LID'] = this.deliverplan.LID
				let data = e.detail.value
				postupdate(953801, global.userinfo.lusercode, {
					'table': data
				}).then(res => {
					if (res.code == 1) {
						global.Return = true
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 500)
						uni.showToast({
							title: '修改成功',
							icon: 'success',
							duration: 3000
						});
					} else {
						uni.showToast({
							title: '修改失败',
							icon: 'none',
						});
					}
				})
			},
			formReset() {

			}
		}
	}
</script>

<style lang="scss">
</style>
